package com.woniuxy.service.impl;

import com.woniuxy.dao.OrderMapper;
import com.woniuxy.pojo.CustomerPrice;
import com.woniuxy.pojo.DatePrice;
import com.woniuxy.pojo.Order;
import com.woniuxy.service.OrderService;
import com.woniuxy.util.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


@Service
public class OrderServiceImpl implements OrderService {


    @Autowired
    private OrderMapper orderMapper;

    @Override
    public DataGridView selectOrderByOrdeCustNo(String ordeCustNo) {
        List<Order> orders = orderMapper.selectOrderByOrdeCustNo(ordeCustNo);
        return new DataGridView(Long.valueOf(orders.size()),orders);
    }

    /**
     * 查询所有客户的贡献，就是得到该客户贡献了的总金额，以便我们分析报表
     * @return
     */
    @Override
    public List<CustomerPrice> findCustomerPriceTotal() {
        return orderMapper.selectCustomerPriceTotal();
    }

    /**
     * 这个是年限对应的总金额,年金额
     * @return
     */
    @Override
    public List<DatePrice> findYearDatePrice() {
        return orderMapper.selectDatePrice();
    }
    @Override
    public void addOrder(String custNo) {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date=sdf.format(new Date());
            orderMapper.addOrder(custNo,date);
    }
}